package com.garbuz.svnadmin.data
{
	import com.garbuz.svnadmin.dto.PermissionTO;

	public class Permission
	{
		public static function fromTO(data:PermissionTO):Permission
		{
			var permission:Permission = new Permission();
			permission.name = data.name;
			permission.readonly = data.readonly;
			permission.isGroup = data.isGroup;

			return permission;
		}
		
		public static function toTO(permission:Permission):PermissionTO
		{
			var data:PermissionTO = new PermissionTO();
			data.name = permission.name;
			data.readonly = permission.readonly;
			data.isGroup = permission.isGroup;

			return data;
		}

		[Bindable]
		public var name:String;

		[Bindable]
		public var readonly:Boolean;

		[Bindable]
		public var isGroup:Boolean;
		
		public function get label():String
		{
			return isGroup ? Group.getLabel(name) : name;
		}

		//noinspection JSUnusedGlobalSymbols
		public function get sortOrder():String
		{
			return isGroup ? " " + name : name;
		}

		public function clone():Permission
		{
			var permission:Permission = new Permission();
			permission.name = name;
			permission.readonly = readonly;
			permission.isGroup = isGroup;

			return permission;
		}

		public function get description():String
		{
			return readonly ? "(readonly)" : "";
		}

	}
}
